package com.software.loginregister;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.WindowManager;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.software.loginregister.activity.TasteSelectionActivity;
import com.software.loginregister.util.SharedPreferencesUtil;
public class StartPageActivity extends AppCompatActivity {

    private static final long SPLASH_DELAY = 2000; // 2秒延迟

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_start_page);

        // 隐藏状态栏和导航栏
        getWindow().setFlags(
                WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN
        );

        // 找到需要添加动画的视图


        TextView tvSlogan = findViewById(R.id.tvSlogan);



        



//        判断登录状态，并跳转 到登录界面
        new Handler(Looper.getMainLooper()).postDelayed(() -> {
            Intent intent;
            if (SharedPreferencesUtil.isLoggedIn(this)) {
                // 已登录，检查是否已选择过口味
                if (SharedPreferencesUtil.isTasteSelected(this)) {
                    // 已选择过口味，直接进入主页
                    intent = new Intent(this, MainActivity.class);
                } else {
                    // 未选择过口味，进入口味选择页面
                    intent = new Intent(this, TasteSelectionActivity.class);
                }
            } else {
                // 未登录，进入登录页
                intent = new Intent(this, LoginActivity.class);
            }
            startActivity(intent);
            finish();
        }, SPLASH_DELAY);

    }
}